package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.shiro.ShiroUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("seller")
public class SellerController {
    @DubboReference
    private SellerService sellerService;

    @RequestMapping("add")
    @ResponseBody
    public Result add(TbSeller tbSeller){
        String salt = ShiroUtils.generateSalt(3);
        String md5 = ShiroUtils.encryptPassword("MD5", tbSeller.getPassword(), salt, 3);
        tbSeller.setPassword(md5);
        tbSeller.setSalt(salt);
        Integer i = sellerService.add(tbSeller);
        if (i == 1){
            return Result.ok();
        }else {
            return Result.response(ResultEnum.HASID);
        }
    }

}
